/**
 * 给你一个字符串 s，找到 s 中最长的 回文子串
 */

/**
 * @param {string} s
 * @return {string}
 */
var longestPalindrome = function (s) {
    let n = s.length;
    let res = '';
    for (let i = 0; i < n; i++) {
        let len1 = expandAroundCenter(i, i);
        let len2 = expandAroundCenter(i, i + 1);
        let len = Math.max(len1, len2);
        if (len > res.length) {
            res = s.substring(i - (len - 1) / 2, i + len / 2 + 1);
        }
    }

    function expandAroundCenter(left, right) {
        while (left >= 0 && right < s.length && s.charAt(left) === s.charAt(right)) {
            left--;
            right++;
        }
        return right - left - 1;
    }
    return res;
};